package com.livestocksolutions;

import java.util.ArrayList;

/* -- Version History --
 *  1.0 : 22 July 2012 - Initial version.
 */

/**
 * This class stores all monetary transactions that have occurred in relation to Bovines
 * @author Adam Parr
 * @version 1.0
 * 
 * @.modified 22 July 2012
 */
public class Finance {
	/**
	 * This ArrayList stores all monetary transactions that have occurred in relation to Bovines
	 */
	private ArrayList<Transaction> transactions = new ArrayList<Transaction>();
	
	/**
	 * Keeps count of the number of Transactions that have been created so that each Transaction has a unique ID
	 */
	private int transactionCounter = 0;
	
	/**
	 * Get an array of all Transactions
	 * @return an array of all Transactions
	 */
	public Transaction[] getTransactions(){
		return transactions.toArray(new Transaction[] {});
	}
	
	/**
	 * Set the transactions ArrayList to the ArrayList provided
	 * @param transactions new ArrayList to set for transactions
	 */
	public void setTransactions(ArrayList<Transaction> transactions){
		this.transactions=transactions;
	}
	
	/**
	 * Add a new Transaction to this Finance Object
	 * @param transaction the new Transaction to add
	 */
	public void addTransaction(Transaction transaction){
		transactions.add(transaction);
	}
	
	/**
	 * Remove a transaction from this Finance Object
	 * @param transactionID the Transaction to remove
	 * @return <code>true</code> if this transaction was successfully removed, <code>false</code> otherwise
	 */
	public boolean removeTransaction(int transactionID){
		for(Transaction t : transactions){
			if(t.getTransactionID()==transactionID){
				return transactions.remove(t);
			}
		}
		return false;
	}
	
	/**
	 * Get a Transaction
	 * @param transactionID the Transaction to return
	 * @return the Transaction with a transactionID that matches the given transactionID, or <code>null</code> 
	 * if no Transaction exists with that id
	 */
	public Transaction getTransaction(int transactionID){
		for(Transaction t : transactions){
			if(t.getTransactionID()==transactionID){
				return t;
			}
		}
		return null;
	}
	
	/**
	 * Get the current value of the transactionCounter
	 * @return the current value of the transactionCounter
	 */
	public int getTransactionCounter(){
		return transactionCounter;
	}
	
	/**
	 * Changes the value of the transactionCounter to the value provided
	 * @param transactionCounter the new value to set the transactionCounter to
	 * @deprecated Please use {@link #incrementCounter()} instead
	 */
	@Deprecated
	public void setTransactionCounter(int transactionCounter){
		this.transactionCounter=transactionCounter;
	}
	
	/**
	 * Increments a counter that will be able to uniquely assign each transaction to a number.
	 */
	public void incrementCounter() {
		transactionCounter++;
	}
}
